home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////////////////////
- // //
- // Numerator.c for NameNumerator //
- // //
- // © 1996 1 A.M. Productions and J. McCornack //
- // September 9,1996 //
- // //
- // This demonstrates serial encoding based //
- // on ASCII values of the user's name. //
- // Once you have the name converted to a //
- // number, you can manipulate that number //
- // as was done in Serial Generator. //
- // //
- // The game program compares this number //
- // with the user's registered name and number. //
- // //
- //////////////////////////////////////////////////
-
- #ifndef __MAIN__
- #include "Numerator.h"
- #endif
-
- void main()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
-
- GetNumber(); // Ask the user for a name to numerate
-
- FlushEvents(everyEvent,0);
- }
-
- void GetNumber()
- {
- short itemHit, itemType;
- long i;
- Handle itemHandle;
- Rect itemRect;
- Str255 nameStr, nameNum;
- DialogPtr dialog;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- dialog=GetNewDialog(130,nil,(WindowPtr)-1); //130 is NameNumerator dialog ID#
- ShowWindow(dialog);
- SelectWindow(dialog);
- SetPort(dialog);
- GetDialogItem(dialog,3,&itemType,&itemHandle,&itemRect);
- SetDialogItemText(itemHandle,"\pyour name here");
-
- nameStr[0] = 24;
- nameStr[25] = '\0';
- nameNum[0] = 6;
- nameNum[7] = '\0';
- itemHit=-1;
-
- while (itemHit !=2)
- {
- ModalDialog(StdFilter, &itemHit);
-
- if (itemHit == 2)
- {
- SetPort(oldPort);
- DisposeDialog(dialog);
- ExitToShell();
- }
- if (itemHit == 1)
- {
- for (i=1;i <= 24; i++)
- nameStr[i] = '\0';
- GetDialogItem(dialog,3,&itemType,&itemHandle,&itemRect);
- GetDialogItemText(itemHandle,nameStr);
- GetValue(nameStr, nameNum);
- GetDialogItem(dialog,4,&itemType,&itemHandle,&itemRect);
- SetDialogItemText(itemHandle,nameNum);
- SysBeep(1);
- }
- }
- }
-
- pascal Boolean StdFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
- {
- char theChar;
- short itemKind;
- Handle itemHandle;
- Rect itemBox;
-
- switch ( theEvent->what )
- {
- case keyDown:
- theChar = (char)(theEvent->message & charCodeMask);
- if ( (((theEvent->modifiers & cmdKey) != 0) && (theChar == '.')) || (theChar == (char)27) ) /*cmd-. or ESC*/
- {
- *itemHit = kCancelButton;
- GetDItem(theDialog, kCancelButton, &itemKind, &itemHandle, &itemBox);
- HiliteControl((ControlHandle)itemHandle, 1);
- return true;
- }
- if ( (theChar == (char)13) || (theChar == (char)3) )
- {
- *itemHit = kOKButton;
- GetDItem(theDialog, 1, &itemKind, &itemHandle, &itemBox);
- HiliteControl((ControlHandle)itemHandle, kOKButton);
- return true;
- }
- break;
- case updateEvt:
- BeginUpdate(theDialog);
- SetPort(theDialog);
- DrawDialog(theDialog);
- GetDItem(theDialog, kOKButton, &itemKind, &itemHandle, &itemBox);
- InsetRect(&itemBox, -4, -4);
- PenSize(3, 3);
- FrameRoundRect(&itemBox, 15, 15);
- EndUpdate(theDialog);
- break;
- }
- return false;
- }
-
-
- void GetValue(Str255 valStr, Str255 retStr)
- {
- long i;
-
- for (i=1; i <= 6; i++) //Load first six character codes
- retStr[i] = (valStr[i] % 10);
- for (i=1; i <= 6; i++) //Load next six character codes (7 through 12)
- retStr[i] = ((retStr[i] + valStr[i+6]) % 10);
- for (i=1; i <= 6; i++) //Load third six character codes (13 through 18)
- retStr[i] = ((retStr[i] + valStr[i+12]) % 10);
- for (i=1; i <= 6; i++) //Load first six character codes (19 through 24)
- retStr[i] = ((retStr[i] + valStr[i+18]) % 10);
-
- retStr[1] = ((retStr[1] + 2) % 10) + '0'; //Add 257458 (kinda…) and '0'
- retStr[2] = ((retStr[2] + 5) % 10) + '0';
- retStr[3] = ((retStr[3] + 7) % 10) + '0';
- retStr[4] = ((retStr[4] + 4) % 10) + '0';
- retStr[5] = ((retStr[5] + 5) % 10) + '0';
- retStr[6] = ((retStr[6] + 8) % 10) + '0';
- }